package com.stephen.netty.nio;

import java.nio.IntBuffer;

/**
 * Created by stephen on 2021-03-07 10:44 .
 * Description: Buffer的基本使用
 */
public class BasicBuffer {

    public static void main(String[] args) {
        // 创建一个buffer,大小为5,即可以存放5个int值
        IntBuffer intBuffer = IntBuffer.allocate(5);
        // 向buffer中添加数据
        for (int i = 0; i < intBuffer.capacity(); i++) {
            intBuffer.put(i);
        }
        // 进行buffer的读写切换,如果不切换,无法读取
        intBuffer.flip();
        // 从buffer中取值
        while (intBuffer.hasRemaining()) {
            System.out.println(intBuffer.get());
        }

    }
}
